define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/item/index' + location.search,
                    add_url: 'order/item/add',
                    edit_url: 'order/item/edit',
                    del_url: 'order/item/del',
                    multi_url: 'order/item/multi',
                    import_url: 'order/item/import',
                    table: 'wanlshop_order_item',
                }
            });

            var table = $("#table");

            // table.on('post-common-search.bs.table', function (event, table) {
            //     var form = $("form", table.$commonsearch);
            //     $("input[name='shop.id']", form).addClass("selectpage").data("source", "Ajax/getshoplist?type=arr2").data("primaryKey", "id").data("field", "shopname").data("orderBy", "id desc");
            //     Form.events.cxselect(form);
            //     Form.events.selectpage(form);
            // });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                Search:true,
                commonSearch:true,
                searchFormVisible:true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), visible:false,operate:false},
                        {field: 'order.order_no', title: __('Order.order_no'), operate: 'LIKE'},
                        //{field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'payway.pay_way_id', title: __('payway.pay_way_id'), searchList: {"6":__('payway.pay_way_id 6'),
                                "7":__('payway.pay_way_id 7'),"8":__('payway.pay_way_id 8'),"9":__('payway.pay_way_id 9'),"10":__('payway.pay_way_id 10'),
                                "11":__('payway.pay_way_id 11'),"12":__('payway.pay_way_id 12')},operate: '=', formatter: Table.api.formatter.normal},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4'),"5":__('Type 5')}, formatter: Table.api.formatter.normal},
                        {field: 'user.nickname', title: __('客户名'), operate: 'LIKE'},
                        {field: 'staffs', title: __('销售人员'),operate: false,},
                        {field: 'shop.id', title: '下单门店',searchList:$.getJSON('Ajax/getshoplist?type=arr'), visible:false},
                        {field: 'shop.shopname', title: '下单门店', operate: false},
                        {field: 'price', title: __('Price'), operate:false},
                        {field: 'actual_price', title: __('Actual_price'), operate:false},
                        {field: 'order.state', title: __('Order.state'), searchList: {"1":__('State 1'),"2":__('State 2'),"3":__('State 3'),"4":__('State 4'),"6":__('State 6'),"7":__('State 7'),"8":__('State 8'),"9":__('State 9'),"10":__('State 10'),"11":__('State 11'),"12":__('State 12'),"13":__('State 13')}, formatter: Table.api.formatter.normal},
                        {field: 'order.paymenttime', title: __('Order.paymenttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.createtime', title: __('Order.Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'validity', title: __('Validity'), searchList: {"0":__('Validity 0'),"1":__('Validity 1'),"3":__('Validity 3')}, formatter: Table.api.formatter.normal},
                        // {field: 'validitytime', title: __('Validitytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},

                        // {field: 'item_id', title: __('Item_id')},
                        // {field: 'order_id', title: __('Order_id')},
                        // {field: 'shop_id', title: __('Shop_id')},
                        // {field: 'user_id', title: __('User_id')},
                       
                        // {field: 'category_id', title: __('Category_id')},
                        // {field: 'name', title: __('Name'), operate: 'LIKE'},
                        // {field: 'code', title: __('Code'), operate: 'LIKE'},
                        // {field: 'consumption', title: __('Consumption'), searchList: {"1":__('Consumption 1'),"2":__('Consumption 2'),"3":__('Consumption 3'),"4":__('Consumption 4')}, formatter: Table.api.formatter.normal},
                       
                        // {field: 'save_price', title: __('Save_price'), operate:'BETWEEN'},
                      
                        // {field: 'specs', title: __('Specs'), searchList: {"1":__('Specs 1'),"2":__('Specs 2')}, formatter: Table.api.formatter.normal},
                       
                        // {field: 'gift', title: __('Gift'), operate:'BETWEEN'},
                        // {field: 'spent', title: __('Spent')},
                        // {field: 'total', title: __('Total')},
                        // {field: 'validity', title: __('Validity'), searchList: {"0":__('Validity 0'),"1":__('Validity 1'),"3":__('Validity 3')}, formatter: Table.api.formatter.normal},
                        // {field: 'validitytime', title: __('Validitytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'validitydays', title: __('Validitydays'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'shop_ids', title: __('Shop_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'stock', title: __('Stock'), searchList: {"0":__('Stock 0'),"2":__('Stock 2'),"3":__('Stock 3')}, formatter: Table.api.formatter.normal},
                        // {field: 'activity', title: __('Activity'), searchList: {"0":__('Activity 0'),"1":__('Activity 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'distribution', title: __('Distribution'), searchList: {"0":__('Distribution 0'),"1":__('Distribution 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'flag', title: __('Flag'), searchList: {"type":__('Flag type'),"name":__('Flag name'),"rec":__('Flag rec')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        // {field: 'activity_type', title: __('Activity_type'), searchList: {"goods":__('Activity_type goods'),"groups":__('Activity_type groups'),"seckill":__('Activity_type seckill'),"bargain":__('Activity_type bargain')}, formatter: Table.api.formatter.normal},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        // {field: 'user.id', title: __('User.id')},
                        // {field: 'user.group_id', title: __('User.group_id')},
                        // {field: 'user.shop_id', title: __('User.shop_id')},
                        // {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                       
                        // {field: 'user.password', title: __('User.password'), operate: 'LIKE'},
                        // {field: 'user.salt', title: __('User.salt'), operate: 'LIKE'},
                        // {field: 'user.email', title: __('User.email'), operate: 'LIKE'},
                       
                        // {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'user.level', title: __('User.level')},
                        // {field: 'user.gender', title: __('User.gender')},
                        // {field: 'user.birthday', title: __('User.birthday'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'user.bio', title: __('User.bio'), operate: 'LIKE'},
                        // {field: 'user.money', title: __('User.money'), operate:'BETWEEN'},
                        // {field: 'user.score', title: __('User.score')},
                        // {field: 'user.successions', title: __('User.successions')},
                        // {field: 'user.maxsuccessions', title: __('User.maxsuccessions')},
                        // {field: 'user.prevtime', title: __('User.prevtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.logintime', title: __('User.logintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.loginip', title: __('User.loginip'), operate: 'LIKE'},
                        // {field: 'user.loginfailure', title: __('User.loginfailure')},
                        // {field: 'user.loginfailuretime', title: __('User.loginfailuretime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.joinip', title: __('User.joinip'), operate: 'LIKE'},
                        // {field: 'user.jointime', title: __('User.jointime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.createtime', title: __('User.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.updatetime', title: __('User.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.token', title: __('User.token'), operate: 'LIKE'},
                        // {field: 'user.status', title: __('User.status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        // {field: 'user.verification', title: __('User.verification'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'user.code', title: __('User.code'), operate: 'LIKE'},
                        // {field: 'user.juser_id', title: __('User.juser_id')},
                        // {field: 'user.remark', title: __('User.remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'order.id', title: __('Order.id')},
                        // {field: 'order.user_id', title: __('Order.user_id')},
                        // {field: 'order.shop_id', title: __('Order.shop_id')},
                        
                        // {field: 'order.address_id', title: __('Order.address_id')},
                        // {field: 'order.coupon_id', title: __('Order.coupon_id')},
                        // {field: 'order.isaddress', title: __('Order.isaddress')},
                        // {field: 'order.freight_type', title: __('Order.freight_type')},
                        // {field: 'order.express_name', title: __('Order.express_name'), operate: 'LIKE'},
                        // {field: 'order.express_no', title: __('Order.express_no'), operate: 'LIKE'},
                       
                        // {field: 'order.remarks', title: __('Order.remarks'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'order.createtime', title: __('Order.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.paymenttime', title: __('Order.paymenttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.delivertime', title: __('Order.delivertime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.taketime', title: __('Order.taketime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.dealtime', title: __('Order.dealtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.updatetime', title: __('Order.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.deletetime', title: __('Order.deletetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.status', title: __('Order.status'), formatter: Table.api.formatter.status},
                        // {field: 'order.price', title: __('Order.price'), operate:'BETWEEN'},
                        // {field: 'order.save_prcie', title: __('Order.save_prcie'), operate:'BETWEEN'},
                        // {field: 'order.actual_price', title: __('Order.actual_price'), operate:'BETWEEN'},
                        // {field: 'shop.id', title: __('Shop.id')},
                        // {field: 'shop.user_id', title: __('Shop.user_id')},
                      
                        // {field: 'shop.keywords', title: __('Shop.keywords'), operate: 'LIKE'},
                        // {field: 'shop.description', title: __('Shop.description'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'shop.service_ids', title: __('Shop.service_ids'), operate: 'LIKE'},
                        // {field: 'shop.avatar', title: __('Shop.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'shop.state', title: __('Shop.state')},
                        // {field: 'shop.level', title: __('Shop.level')},
                        // {field: 'shop.islive', title: __('Shop.islive')},
                        // {field: 'shop.isself', title: __('Shop.isself')},
                        // {field: 'shop.city', title: __('Shop.city'), operate: 'LIKE'},
                        // {field: 'shop.return', title: __('Shop.return'), operate: 'LIKE'},
                        // {field: 'shop.like', title: __('Shop.like')},
                        // {field: 'shop.score_describe', title: __('Shop.score_describe'), operate:'BETWEEN'},
                        // {field: 'shop.score_service', title: __('Shop.score_service'), operate:'BETWEEN'},
                        // {field: 'shop.score_deliver', title: __('Shop.score_deliver'), operate:'BETWEEN'},
                        // {field: 'shop.score_logistics', title: __('Shop.score_logistics'), operate:'BETWEEN'},
                        // {field: 'shop.weigh', title: __('Shop.weigh')},
                        // {field: 'shop.verify', title: __('Shop.verify')},
                        // {field: 'shop.createtime', title: __('Shop.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'shop.updatetime', title: __('Shop.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'shop.deletetime', title: __('Shop.deletetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'shop.status', title: __('Shop.status'), formatter: Table.api.formatter.status},
                        // {field: 'shop.code', title: __('Shop.code'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'shop.type', title: __('Shop.type')},
                        // {field: 'shop.auth_id', title: __('Shop.auth_id')},
                        // {field: 'shop.person', title: __('Shop.person'), operate: 'LIKE'},
                        // {field: 'shop.telephone', title: __('Shop.telephone'), operate: 'LIKE'},
                        // {field: 'shop.staff_id', title: __('Shop.staff_id')},
                        // {field: 'shop.maturitytime', title: __('Shop.maturitytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'shop.payment', title: __('Shop.payment'), operate:'BETWEEN'},
                        // {field: 'shop.settled', title: __('Shop.settled'), operate:'BETWEEN'},
                        // {field: 'shop.adds', title: __('Shop.adds'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, 
                        
                        buttons: [
                            {
                                name: 'detail',
                                text: '查看/编辑',
                                title: '查看/编辑',
                                icon: '',
                                extend: 'data-area=\'["90%", "90%"]\'',
                                classname: 'btn btn-xs btn-success btn-dialog',
                                url: "order/item/detail",
                            }],
                        formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'order/item/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'order/item/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'order/item/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
